// noinspection NpmUsedModulesInstalled,JSFileReferences
import BaseConstants from '@/constant/base_constants.js'

class HttpUtils {
	static async getAsync(url, params) {
		if (params === null || params === undefined) {
			params = {}
		}
		params.method = 'GET'
		return await fetch(url, params).then(response => response.json())
			.then(result => result)
	}

	static async postAsync(url, params) {
		if (params === null || params === undefined) {
			params = {}
		}
		params.method = 'POST'
		if (params.headers === undefined || params.headers === null) {
			params.headers = {}
		}
		if (params.headers['Content-Type'] === undefined || params.headers['Content-Type'] === null
			|| params.headers['Content-Type'] === BaseConstants.EMPTY_STR) {
			params.headers['Content-Type'] = 'application/json'
		}

		console.log('post params:' + JSON.stringify(params))
		let response = await fetch(url, params)
		return await response.json()
	}
}

export default HttpUtils